﻿@model IEnumerable<System.Web.Mvc.SelectListItem>
@{
    int repeatColumns = Convert.ToInt32(ViewData["RepeatColumns"]);
    Func<dynamic, object> itemTemplate = ViewData["ItemTemplate"] as Func<dynamic, object>;
}
@if (this.Model != null)
{
    int idx = 0;
    int total = Model.Count();
    <div class="checkbox-list">
        @foreach (var obj in this.Model)
        {
            if (repeatColumns > 0 && idx % repeatColumns == 0)
            {
            @:<div class="checkbox-row">
            } 
            <input type="checkbox" id="cb_@(obj.Value)" name="cb_@(obj.Value)" value="@obj.Value" @((obj.Selected ? "checked='checked'" : "").ToHtmlString()) /> <label for="cb_@(obj.Value)">@obj.Text</label>
            if (itemTemplate != null) 
            { 
                @itemTemplate(obj) 
            } 
            if (repeatColumns > 0 && (idx % repeatColumns == repeatColumns - 1 || idx == total - 1)) 
            { 
                @:</div> 
            }
    }
    </div>
}